﻿<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class Mcustomer extends CI_Model
	{
		function __construct()
		{
			//parent::CI_Model();	
		}

		public function get_ctmers($pageindex,$pageSize)
		{
			$str = '';			
			$page_num1 = (int) $pageindex;
           // $page_num1 >0 ? $page_num1 = $page_num1 -1: $page_num1 = $page_num1 ;
			$l_num = $page_num1 * $pageSize;
			$nbg = $this->input->get('nbg');
            $order = $this->input->get('order');
            //echo $nbg;		
                        $this->db->from('wtt_customers');
                        if(!empty($nbg)){
                            $this->db->like('screen_name',$nbg);
                        }
                        switch($order){
                            case 1:
                              $this->db->order_by('followers_count','desc');  
                            case 2:
                               $this->db->order_by('reg_time','desc'); 
                            case 3:
                                $this->db->order_by('status','desc');
                            default:
                               $this->db->order_by('reg_time','desc');   
                        }
                        $this->db->order_by('reg_time','desc');
                        $this->db->limit($pageSize, $l_num);
                        $query = $this->db->get();
			$gender = array('f'=>'女','m'=>'男','n'=>'未知');
			foreach ($query->result_array() as $row) {
				$str.= "<tr align=\"center\">";
				$str.= "<td><a href='http://weibo.com/u/".$row['wb_id']."'>".$row['wb_id']."</a></td>";
                                $str.= "<td>".$row['screen_name']."</td>";
                                $str.= "<td>".$row['location']."</td>";
                                $str.= "<td>".$gender[$row['gender']]."</td>";
                                $str.= "<td>".$row['followers_count']."</td>
";
                                $str.= "<td>".$row['jifen']."</td>";
			        $str.= "<td>".date('Y-n-j H:i:s',$row['reg_time'])."</td>";
                                $str.= "<td><a href=\"javascript:aa('#chongzhi',".$row['wb_id'].",'".$row['screen_name']."',0);\">充值</a> |  <a href=\"javascript:aa('#setuser',".$row['wb_id'].",'".$row['screen_name']."',".$row['status'].");\">状态</a> | <a href=\"".site_url('tlianmengs/get_uidc')."/".$row['wb_id']."/0\" target=\"_blank\">查看收支</a></td>";
				$str.= "</tr>";
			}
			return $str;
			
		}
                function get_reposts($pageindex,$pageSize)
                {
                        $str = '';			
			$page_num1 = (int) $pageindex;
           // $page_num1 >0 ? $page_num1 = $page_num1 -1: $page_num1 = $page_num1 ;
			$l_num = $page_num1 * $pageSize;
			$sql = "SELECT a.id,a.uid,a.content,a.rp_num,a.rp_points,a.rptime,a.wb_text,a.thumbnail_pic,a.r_text,a.r_pic,b.screen_name from  wtt_repost a JOIN wtt_customers b ON a.uid=b.wb_id order by a.rptime desc LIMIT $l_num,$pageSize";
			$query = $this->db->query($sql);
			
			foreach ($query->result_array() as $row) {
				$w_text = $row['wb_text'].'<br />转发内容：'. $row['r_text'];
                                $r_m = empty($row['r_pic']) ? $row['thumbnail_pic'] : $row['r_pic'];
                                $r_m = empty($r_m) ? '' : '<a href="'.$r_m.'" target="_blank"><img src="'.$r_m.'" /></a>' ;
                                $str.= "<tr align=\"center\">";
				$str.= "";
                                $str.= "<td>".$row['screen_name']."</td>";
                                $str.= "<td>".$r_m ."</td>";
                                $str.= "<td>".$w_text."</td>";
                                $str.= "<td>".$row['rp_points']."</td><td>".$row['rp_num']."</td>";
                                $str.= "<td>".date('Y-n-j H:i:s',$row['rptime'])."</td>";
                                $str.= "<td><a href=\"".  site_url('tlianmengs/delrepost/'.$row['id'].'/'.$this->session->userdata('session_id'))."\" onclick=\"return confirm('确定要删除');\">删除</a></td>";
				$str.= "</tr>";
			}
			return $str;
                }
                
                
              
        function get_paylist($pageindex,$pageSize)
                {
                        $str = '';			
			$page_num1 = (int) $pageindex;
           // $page_num1 >0 ? $page_num1 = $page_num1 -1: $page_num1 = $page_num1 ;
			$l_num = $page_num1 * $pageSize;
			$sql = "SELECT a.order_id,a.pro_id,a.wb_id,a.create_time,a.order_status,b.screen_name from wtt_payorder a JOIN wtt_customers b ON a.wb_id=b.wb_id order by a.create_time desc LIMIT $l_num,$pageSize";
			$query = $this->db->query($sql);
			
			foreach ($query->result_array() as $row) {
				
                                
                                
                                $str.= "<tr align=\"center\">";
				$str.= "<td><a href='http://weibo.com/u/".$row['wb_id']."'>".$row['wb_id']."</a></td>";
                                $str.= "<td>".$row['screen_name']."</td>";
                                $str.= "<td>".$row['order_id'] ."</td>";
                                $str.= "<td>".$row['pro_id']."</td>";
                                $str.= "<td>"."</td>";
                                $str.= "<td>".date('Y-n-j H:i:s',$row['create_time'])."</td>";
                                $str.= "<td>".$this->getstr($row['order_status'],$row['order_id'])."</td>";
				$str.= "</tr>";
               
			}
			return $str;
             }  

             function get_transferlist($pageindex,$pageSize)
                {
                        $str = '';          
            $page_num1 = (int) $pageindex;
           // $page_num1 >0 ? $page_num1 = $page_num1 -1: $page_num1 = $page_num1 ;
            $l_num = $page_num1 * $pageSize;
            $sql = "SELECT a.uid,a.touid,a.nickname,b.screen_name as tonickname,a.datatime,a.points,a.paytype from wtt_pays a JOIN wtt_customers b on a.touid=b.wb_id   where a.types='11'  order by a.datatime desc LIMIT $l_num,$pageSize";
            $query = $this->db->query($sql);
            
            foreach ($query->result_array() as $row) {
                
                                 
                                
                                $str.= "<tr align=\"center\">";
                $str.= "<td><a href='http://weibo.com/u/".$row['uid']."'>".$row['uid']."</a></td>";
                                $str.= "<td>".$row['nickname']."</td>";
                                $str.= "<td><a href='http://weibo.com/u/".$row['touid']."'>".$row['touid']."</a></td>";
                                 $str.= "<td>".$row['tonickname']."</td>";
                                $str.= "<td>".$row['points']."</td>";
                                $str.= "<td>".date('Y-n-j H:i:s',$row['datatime'])."</td>";                                 
                $str.= "</tr>";
               
            }
            return $str;
             }  

             function get_transferlist_num()
                {
                        $num=0;
                        $sql = "SELECT a.uid,a.touid,a.nickname,b.screen_name as tonickname,a.datatime,a.points,a.paytype from wtt_pays a JOIN wtt_customers b on a.touid=b.wb_id   where a.types='11'  ";
                        $num= $this->db->num($sql);
                        return $num;
             }  

                function get_exchangelist_num()
                {
                        $num=0;
                        $sql = "SELECT a.goods,a.wb_id,a.create_time,a.coins,b.screen_name as nickname  from wtt_exchangeorder a  JOIN wtt_customers b on a.wb_id=b.wb_id ";
                        $num= $this->db->num($sql);
                        return $num;
             }  
             function get_exchangelist($pageindex,$pageSize)
                {
                        $str = '';          
            $page_num1 = (int) $pageindex;
           // $page_num1 >0 ? $page_num1 = $page_num1 -1: $page_num1 = $page_num1 ;
            $l_num = $page_num1 * $pageSize;
            $sql = "SELECT a.goods,a.wb_id,a.create_time,a.coins,b.screen_name as nickname  from wtt_exchangeorder a  JOIN wtt_customers b on a.wb_id=b.wb_id     order by a.create_time desc LIMIT $l_num,$pageSize";
            $query = $this->db->query($sql);
            
            foreach ($query->result_array() as $row) {
                
                                 
                                
                                $str.= "<tr align=\"center\">";
                $str.= "<td><a href='http://weibo.com/u/".$row['wb_id']."'>".$row['wb_id']."</a></td>";
                                $str.= "<td>".$row['nickname']."</td>";
                                $str.= "<td>".$row['goods']."</td>";
                                 $str.= "<td>".$row['coins']."</td>";                              
                                $str.= "<td>".date('Y-n-j H:i:s',$row['create_time'])."</td>";                                 
                $str.= "</tr>";
               
            }
            return $str;
             } 


                
                function getstr($num,$ordernum)
                {
                    if($num == 0)
                    {
                        return "<a href=\"javascript:aa(".$ordernum.");\">待支付</a>";
                    }
                    if($num == 1)
                    {
                        return "充值成功";
                    }
                } 

		public function get_address($pageindex,$pageSize)
		{
			$str = '';			
			$page_num1 = (int) $pageindex;
       
			$l_num = $page_num1 * $pageSize;
			$nbg = $this->input->get('nbg');
           
            		   $this->db->from('wtt_addres');
                        if(!empty($nbg)){
                            $this->db->like('screen_name',$nbg);
                        }
                        $this->db->order_by('add_time','desc');   
                        $this->db->limit($pageSize, $l_num);
                        $query = $this->db->get();
		
			foreach ($query->result_array() as $row) {
			  if(!empty($row['cust_id']) || $row['cust_id']!=''){
				$str.= "<tr align=\"center\">";
				$str.= "<td>".$row['cust_id']."</td>";
				
                                $str.= "<td>".$row['screen_name']."</td>";
                                $str.= "<td>".$row['order_id']."</td>";
                                $str.= "<td>".$row['lianxiren']."</td>";
                                $str.= "<td>".$row['phone']."</td>";
                                $str.= "<td>".$row['addressinfo']."</td>";
                                $str.= "<td>".$row['youbian']."</td>";
				$str.= "<td>".date('Y-n-j H:i:s',$row['add_time'])."</td>";
				if($row['status'] == 1)
				{
				    $str.= "<td> 已发货</td>";
				}
				else
				{
					 $str.= "<td> <a title='点击修改为发货' href=\"javascript:aa('#setuser',".$row['cust_id'].",'".$row['screen_name']."',".$row['status'].",".$row['address_id'].",".$row['order_id'].");\">未发货</a></td>";
				}
                              
				$str.= "</tr>";
 			    }
			}
			return $str;
			
		}
		
		public function get_makaaddress($pageindex,$pageSize)
		{
			$str = '';			
			$page_num1 = (int) $pageindex;
       
			$l_num = $page_num1 * $pageSize;
			$nbg = $this->input->get('nbg');
           
            		   $this->db->from('wtt_addres');
                        if(!empty($nbg)){
                            $this->db->like('screen_name',$nbg);
                        }
                        $this->db->order_by('add_time','desc');   
                        $this->db->limit($pageSize, $l_num);
                        $query = $this->db->get();
		
			foreach ($query->result_array() as $row) {
		            if(empty($row['cust_id']) || $row['cust_id']==''){
				$str.= "<tr align=\"center\">";
				
				$str.= "<td>".$row['productname']."</td>";
				
				$str.= "<td>".$row['num']."</td>";
                              
                                $str.= "<td>".$row['order_id']."</td>";
                                $str.= "<td>".$row['lianxiren']."</td>";
                                $str.= "<td>".$row['phone']."</td>";
                                $str.= "<td>".$row['addressinfo']."</td>";
                                $str.= "<td>".$row['youbian']."</td>";
				$str.= "<td>".date('Y-n-j H:i:s',$row['add_time'])."</td>";
				$str.= "<td>".$row['liuyan']."</td>";
                                $str.= "<td>".$row['userid']."</td>";
				   $str.= "<td>".$row['paystatus']."</td>";
				if($row['status'] == 1)
				{
				    $str.= "<td> 已发货</td>";
				}
				else
				{
					 $str.= "<td> <a title='点击修改为发货' href=\"javascript:aa('#setuser','234',0,".$row['status'].",".$row['address_id'].",".$row['order_id'].");\">未发货</a></td>";
				}
                              
				$str.= "</tr>";
			    }
			}
			return $str;
			
		}
		
	}